using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using JlPay.Sdk.Core;
using JlPay.Sdk.Services.Openmerch.Change;
using JlPay.Sdk.Models.Openmerch.Change;

namespace JlPay.Sdk.Examples.Openmerch.Change
{
    /// <summary>
    /// 开放商户 - 商户信息变更功能使用示例
    /// </summary>
    public class MerchInfoChangeDemo
    {
        /// <summary>
        /// 构建商户信息变更请求
        /// </summary>
        private static MerchInfoChangeRequest BuildMerchInfoChangeRequest()
        {
            // 构建商户基础信息
            var baseInfo = new Dictionary<string, object>
            {
                ["apply_id"] = "b8659ea518d14c99b78b5ad000a0807a",
                ["product_type"] = "01"
            };

            // 构建商户业务信息
            var businessInfo = new Dictionary<string, object>
            {
                ["merch_no"] = "849584358140108"  // 使用cursor中的商户号
            };

            // 构建商户身份信息
            var identificationInfo = new Dictionary<string, object>
            {
                ["id_card_name"] = "张三",                    // 经营者/法人姓名
                ["id_card_english_name"] = "Zhang San",      // 经营者/法人英文名称
                ["id_card_no"] = "445221199705024935",      // 经营者/法人身份证件号码
                ["legal_person_phone"] = "13800138000",     // 经营者/法人手机号码
                ["license_name"] = "北京科技有限公司",        // 商户法定名称
                ["business_scope"] = "软件开发、技术服务",    // 经营范围
                ["license_address"] = "北京市朝阳区xxx街道",  // 注册地址
                ["license_pic"] = "group1/M00/5E/DB/rBQFm2cRyWGAUF_zAAS9l9WA_pE1351477"
            };

            var request = new MerchInfoChangeRequest
            {
                BaseInfo = baseInfo,
                BusinessInfo = businessInfo,
                IdentificationInfo = identificationInfo
            };

            return request;
        }

        /// <summary>
        /// 商户信息变更示例
        /// </summary>
        public static async Task MerchInfoChangeDemoAsync()
        {
            Console.WriteLine("开始执行商户信息变更示例");

            // 使用DemoConfig创建配置对象
            var config = DemoConfig.CreateConfigWithCrypto();
            Console.WriteLine("配置初始化完成，已启用自动加密和解密功能");

            var changeService = new ChangeService(config);

            // 创建商户信息变更请求
            var request = BuildMerchInfoChangeRequest();

            try
            {
                // 发送请求
                var response = await changeService.ChangeMerchInfoAsync(request);

                // 使用优化的响应处理
                response.HandleResponse("商户信息变更", config);
            }
            catch (Exception ex)
            {
                // 使用优化的异常处理
                var response = new MerchInfoChangeResponse();
                response.HandleResponseWithException("商户信息变更", config, ex);
            }

            Console.WriteLine("商户信息变更示例执行完毕");
        }

        /// <summary>
        /// 主程序入口
        /// </summary>
        public static async Task Main(string[] args)
        {
            Console.WriteLine("=" + new string('=', 50));
            Console.WriteLine("===== 商户信息变更示例 开始 =====");
            Console.WriteLine("=" + new string('=', 50));

            await MerchInfoChangeDemoAsync();

            Console.WriteLine("=" + new string('=', 50));
            Console.WriteLine("===== 商户信息变更示例执行完毕 =====");
            Console.WriteLine("=" + new string('=', 50));
        }
    }
} 